package sz.szsmk.citizencard.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import sz.szsmk.citizencard.R
import sz.szsmk.citizencard.databinding.DialogLifeauthorizationBinding
import sz.szsmk.citizencard.util.JumpUtils


/**
 *  author : hyt
 *  date : 2021/3/11
 *  description :
 */
class LifeAuthorizationDialog(var lifeAuthClick: LifeAuthClick) : DialogFragment() {


    companion object{
        fun newInstance( lifeAuthClick: LifeAuthClick): LifeAuthorizationDialog {
            var bundle = Bundle()
            return  LifeAuthorizationDialog(lifeAuthClick)
        }
    }

    lateinit var mViewBinding : DialogLifeauthorizationBinding

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        mViewBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_lifeauthorization, container, false)
        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) //设置背景为透明
        dialog?.setCancelable(false)
        return mViewBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)


        mViewBinding.btnSubmit.setOnClickListener {
            if(mViewBinding.cbPrivacy.isChecked){
                lifeAuthClick?.onClick()
                dismiss()
            }else{
                Toast.makeText(requireContext(),"请勾选协议",Toast.LENGTH_LONG).show();

            }
        }


        mViewBinding.tvPrivacy.setOnClickListener {
            var url1 = "https://m-lcpro.lianchuanghj.com/pages/package-A/login/privacy-policy/index"
            var bundle =  Bundle()
            bundle.putString("url", url1)
            JumpUtils.jumptoNatvie(requireContext(), "webView", 0, bundle)
        }

        mViewBinding.tvPrivacyUser.setOnClickListener {
            var url1 = "https://m-lcpro.lianchuanghj.com/pages/package-A/login/vip-agreement/index"
            var bundle =  Bundle()
            bundle.putString("url", url1)
            JumpUtils.jumptoNatvie(requireContext(), "webView", 0, bundle)
        }

        mViewBinding.ivClose.setOnClickListener { dismiss() }
    }

    interface LifeAuthClick{
        fun onClick()
    }
}